package com.tust.app.service.impl;

import com.tust.app.dao.NewsMapper;
import com.tust.app.domain.News;
import com.tust.app.service.NewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.xml.registry.infomodel.User;
import java.util.Collections;
import java.util.List;

@Service
public class NewsServiceImpl implements NewsService {

    @Autowired
    private NewsMapper newsMapper;

    @Override
    public List<News> newsList() {
        return newsMapper.selectAllNews();
    }

    @Override
    public List<News> search(String title) {
        System.out.println(title);
        if (title != null && title.length() > 0) {
            return newsMapper.selectNewsByTitle(title);
        }else{
            return null;
        }
    }

    @Override
    public Integer addArticle(News news) {
        return newsMapper.writeNews(news);
    }

    @Override
    public News findNewsById(Integer id) {
        return newsMapper.selectNewsById(id);
    }

    @Override
    public boolean modifyNews(News news) {
        return newsMapper.updateNewsById(news);
    }

    @Override
    public boolean delNews(Integer id) {
        return newsMapper.deleteNewsById(id);
    }
}
